<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	</head>
	<body>
		<div dojoType="dijit.layout.ContentPane" class="gridContainer" style="height:500px;width:100%">
			<div id="generatorGrid">
			</div>
		</div>	
		<div style="text-align:right">
			<button dojoType="dijit.form.Button">
				Select
				<script event="onClick" args="event" type="dojo/method">
					var value = dijit.byId( "reportTypeSelect").value;
					if ( dijit.byId( "generatorGrid").selection.getSelected( ).length == 0) {
						dijit.byId( "toaster").setContent( "Select report entity.", "fatal").show( );
						return;
					}
					var xsltId = dijit.byId( "reportTemplatesGrid").selection.getSelected( )[0].id[0];
					if ( value == "Users") {
						var userId = dijit.byId( "generatorGrid").selection.getSelected( )[0].userLogin[0];
						window.open( "/FinalProject/app/reportManagement?reportOp=user_summary&userId="+userId+"&xsltId="+xsltId);
					} else if ( value == "Projects") {
						var projectId = dijit.byId( "generatorGrid").selection.getSelected( )[0].projectId[0];
						window.open( "/FinalProject/app/reportManagement?reportOp=project_summary&projectId="+projectId+"&xsltId="+xsltId);
					} else if ( value == "Instruments") {
						var instrumentId = dijit.byId( "generatorGrid").selection.getSelected( )[0].id[0];
						window.open( "/FinalProject/app/reportManagement?reportOp=instrument_summary&instrumentId="+instrumentId+"&xsltId="+xsltId);
					}
					dijit.byId( "generateDialog").destroyRecursive( );
				</script>
			</button>
		</div>
	</body>
	<script type="text/javascript">
		dojo.addOnLoad( function( ) {
			var value = dijit.byId( "reportTypeSelect").value;
			var layout;
			var query;
			var store;
			if ( value == "Users") {
				layout = Layouts.usersLayout;
				query = { userLogin: "*"};
				store = new dojo.data.ItemFileWriteStore( { url: "/FinalProject/app/userManagement?userOp=user_get_all_list", clearOnClose: true, jsId:"activeStore"  } );				
			} else if ( value == "Projects") {
				layout = Layouts.projectLayout;
				query = { projectName: '*' };
				store = new dojo.data.ItemFileWriteStore( { url : "/FinalProject/app/projectManagement?projectOp=project_get_project_list", clearOnClose: true, jsId:"projectsStore"});				
				
			} else if ( value == "Instruments") {
				layout = Layouts.instrumentLayout;
				query = { type: '*' };
				store = new dojo.data.ItemFileWriteStore( { url : "/FinalProject/app/instrumentManagement?instrumentOp=instrument_list_all", clearOnClose: true, jsId:"instrumentsStore"});				
			}
			var grid = new dojox.grid.DataGrid( {
				structure : layout,
				store	: store,
				query : query
			}, "generatorGrid");
			grid.startup( );
		});
	</script>
</html>